<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="/billing" prefix="b"%>
<%@page import="com.admin.service.ProvinceService"%>
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1

//or response.setHeader("Cache-Control","no-store");//HTTP 1.1

response.setHeader("Pragma","no-cache"); //HTTP 1.0

response.setDateHeader ("Expires", 0); //prevents caching at the proxy server


String txtDateStart = request.getParameter("txtDateStart");
String phone = request.getParameter("phone");
String spno = request.getParameter("spno");
String mo = request.getParameter("mo");

String table = DateUtil.formatDate(DateUtil.parseDate(txtDateStart),"yyMMdd");


List list = new ArrayList();

String sqlStr = "select recv.org org,recv.dest dest, recv.body body,send.stat stat,recv.tm tm,recv.channel channel,(select cpname from adminuser where id=recv.channel) channelName from recv_"+table+" recv left join send_"+table+" send on recv.linkid = send.linkid where ";
String condition = "";
if(phone!=null && spno!=null &&mo!=null){
	if(!phone.equals("")){
		condition = condition + "recv.org = '"+phone+"' ";
	}
	if(!spno.equals("")){
		condition = condition + " recv.dest like '"+spno+"%' ";
		if(!phone.equals("")){			
			condition = condition + " and recv.dest like '"+spno+"%' ";
		}
	}
	if(!mo.equals("")){
		condition = condition + " recv.body like '"+mo+"%' ";
		if(!phone.equals("")||!spno.equals("")){
			condition = condition + " and recv.body like '"+mo+"%' ";
		}
	}
}

sqlStr = sqlStr+condition+" order by recv.tm desc";
System.out.println("查询日志："+sqlStr);
list = SqlUtil.getObjectsList(sqlStr,DbOperation.DB_MUZHI);
//list = SqlUtil.getObjectsList("select recv.org as org,recv.dest as dest, recv.body as body,send.stat as stat,recv.tm as tm from recv_"+table+" as recv "+
	//	"+left join send_"+table+" as send on recv.linkid = send.linkid where recv.org = '"+phone+"' order by recv.tm desc", DbOperation.DB_MUZHI);

%>

<%@page import="com.admin.util.DateUtil"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.admin.util.SqlUtil"%>
<%@page import="com.admin.util.db.DbOperation"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计费后台管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/managercss.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/wbox.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/wbox.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/validate.js"></script>
<script language="javascript" src="<%=request.getContextPath() %>/PopupCalendar/popup.js"></script>
<script type="text/javascript">
<!--
	$(function(){
		$(".list div").mousemove(function(){
			$(this).css("background","#E3EEFF");
		}).mouseout(function(){
			$(this).css("background","");
		});
		$("#provinceId").val('${provinceId}');
		$("#isp").val('${isp}');
		$("#vodCustomized").val('${vodCustomized}');
	});

	function del(spId){
		if(confirm("你确认删除该SP吗?")){
			$.ajax({
				url:"<%=request.getContextPath() %>/admin/sp/del/"+spId,
				type:"GET",
				success:function(flag){
					if(flag=='1'){
						alert("删除成功!");
						window.location.reload();
					}else{
						alert("删除失败!");
					}
				}
			});
		}
	}
	function addSp(){
		var wBox = $("#ajax").wBox({
			requestType: "iframe",
			iframeWH:{width:700,height:600},
			target:"<%=request.getContextPath() %>/admin/sp/toadd",
			title: "添加新的SP"
		});
		wBox.showBox();
	}

	function back(){
		location.href="<%=request.getContextPath() %>/admin/company";
	}
	
	function fenpei(spid){
		var wBox = $("#ajax").wBox({
			requestType: "iframe",
			iframeWH:{width:700,height:600},
			target:"<%=request.getContextPath() %>/admin/sp/tofenpei/"+spid,
			title: "分配SP通道"
		});
		wBox.showBox();
	}

	function show(spId){
		var wBox = $("#ajax").wBox({
			requestType: "iframe",
			iframeWH:{width:700,height:600},
			target:"<%=request.getContextPath() %>/admin/sp/"+spId,
			title: "查看SP"
		});
		wBox.showBox();
	}
//-->
</script>
</head>
<body>
<div class="information">
	<div class="title">
		上行查询
	</div>
	<div class="search">
		<form action="<%=request.getContextPath() %>/manage/search/recvSend.jsp" method="post">
		时间：<input name="txtDateStart" type="text" readonly="readonly" value="<%=DateUtil.formatDate(new Date()) %>" id="txtDate" OnClick="calendar()" />
		号码：<input type="text" name="phone" value=""/>
		端口号：<input type="text" name="spno" value=""/>
		指令：<input type="text" name="mo" value=""/>
		<input type="submit" value="查询">
		</form>
	</div>
	
	
	<table align="left" width="98%">
		<tr class="list" align="left">
			<td style="width:40px;">编号</td>
			<td style="width:80px;">手机号码</td>
			<td style="width:80px;">端口号</td>
			<td style="width:80px;">指令</td>
			<td style="width:80px;">状态</td>
			<td style="width:200px;">时间</td>
			<td style="width:50px;">渠道</td>
			<td style="width:50px;">渠道名称</td>
		</tr>
		<%
		if(list!=null){
				for(int i = 0;i<list.size();i++) {
					Object[] objs = (Object[])list.get(i);
			%>
				<tr class="list" align="left">
					<td style="width:40px;"><%=i+1%></td>
					<td style="width:80px;"><%=objs[0] %></td>
					<td style="width:80px;"><%=objs[1] %></td>
					<td style="width:80px;"><%=objs[2] %></td>
					<td style="width:80px;">
					<%
					String result = (String)objs[3];
					if("DELIVRD".equals(result)) {%>成功<%} else if(result==null||result.equals("null")||result.equals("NULL")) {%>无下行<%} else {%>失败<%} %></td>
					<td style="width:200px;"><%=objs[4] %></td>
					<td style="width:50px;"><%=objs[5] %></td>
					<td style="width:50px;"><%=objs[6] %></td>
				</tr>
			<%}
		} %>
	
	</table>
	<div class="clear"></div>
	
</div>
</body>
</html>